package com.groups.service;

import java.util.List;

import com.groups.dao.ICommonDAO;
import com.groups.entity.User;

public class UserService {
	private ICommonDAO commonDao;

	public ICommonDAO getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(ICommonDAO commonDao) {
		this.commonDao = commonDao;
	}
	public User checkUser(String userName,String pwd,int power){
		/*String hql = "from User u where u.userName = ?";
		Object[]  args = new Object[]{userName};
		List list = commonDao.list(hql, args);
		if(list.size()!=0&&list!=null){
			User user = (User)list.get(0);
			if(user.getUserPwd().equals(pwd)){
				return user;
			}
			return null;
		}*/
		String hql = "from User u where u.userName = ? and u.userPwd = ? and u.power = ?";
		Object[] args = new Object[]{userName,pwd,power};
		List list = commonDao.list(hql,args);
		if(list.size()!=0&&list!=null){
			User user  = (User) list.get(0);
			return user;
		}
		return null;
	}
	public boolean addUser(User user){
		boolean flag = false;
		if(user.getUserName()!=null){
			commonDao.add(user);
			flag = true;
		}else{
			flag = false;
		}
		return flag ;
	}
}
